import tkinter as tk
from tkinter import filedialog
import os
import shutil

def select_and_extract():
    root = tk.Tk()
    root.withdraw()

    # 选择Minecraft文件夹
    minecraft_folder = filedialog.askdirectory(title="选择Minecraft文件夹")
    
    if not minecraft_folder:
        print("未选择文件夹，操作取消。")
        return

    ftbquests_path = os.path.join(minecraft_folder, "config", "ftbquests")
    
    if not os.path.exists(ftbquests_path):
        print("在选择的文件夹中未找到 config/ftbquests 目录。")
        return

    # 创建 input 和 Data 文件夹（如果不存在）
    input_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "input")
    data_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Data")
    
    os.makedirs(input_folder, exist_ok=True)
    os.makedirs(data_folder, exist_ok=True)

    # 复制文件到 input 文件夹
    try:
        shutil.copytree(ftbquests_path, input_folder, dirs_exist_ok=True)
        print(f"已成功复制文件到 {input_folder}")
    except Exception as e:
        print(f"复制到 input 文件夹时出错: {e}")

    # 复制文件到 Data 文件夹
    try:
        shutil.copytree(ftbquests_path, data_folder, dirs_exist_ok=True)
        print(f"已成功复制文件到 {data_folder}")
    except Exception as e:
        print(f"复制到 Data 文件夹时出错: {e}")

    print("文件提取完成。")

if __name__ == "__main__":
    select_and_extract()

